import { Component } from 'react'
import { View } from '@tarojs/components'
import './index.scss'
import Taro from '@tarojs/taro'
import dayjs from "dayjs"

//组件
import { LgPopLayer } from '../../../../components/popLayer'
import LgButton from '../../../../components/button'

interface IndexState{
  chooseDate?:string
  allPersonCount:number
}

interface IndexProps{
  isOpen:boolean
  data?:any
  onClosePop():void
  deleteItem?(type:1|2|3,item):void
}

export default class PrPopChooseDevices extends Component <IndexProps,IndexState>{
  constructor(props) {
    super(props)
    this.state={
      allPersonCount:0,
    }
    // this.deleteItem = this.deleteItem.bind(this)
  }

  componentWillMount() { }

  componentDidMount() { }

  componentWillUnmount() { }


  deleteItem(type,item){
    this.props.deleteItem?this.props.deleteItem(type,item):""
  }

  isEmpty(data){
    let isEmpty = true
    if(data.buildingBoards.length != 0){
      isEmpty = false
    }
    if(data.classBoard.length != 0){
      isEmpty = false
    }
    if(data.RadioBroadcasts.length != 0){
      isEmpty = false
    }
    if(data?.devics?.length != 0){
      isEmpty = false
    }
    return isEmpty
  }

  render() {
    let data = this.props.data
    let isEmpty = this.isEmpty(data)
    // let allpersonCount = this.getAllpersonCount(data)
    // console.log("弹窗信息",data)
    return (
      <View className='PrPopChooseDevices'>
        <LgPopLayer
            isOpen={this.props.isOpen}
            showLayer={this.props.onClosePop}
            position="bottom"
            title={"已选择设备"}
            showClose
            customContentClass="lg_choObj_select_pop"
        >
          <View className='content'>
            {//楼牌
              data?.buildingBoards?.map((item,index)=>{
                return(
                  <View className='item' key={"admin"+index}>
                    <View className='text'>[楼牌]{item.name}</View>
                    <View className='button' onClick={()=>this.deleteItem(1,item)}>移除</View>
                  </View>
                )
              })
            }
            {//班牌
              data?.classBoard?.map((item,index)=>{
                return(
                  <View className='item' key={"admin"+index}>
                    <View className='text'>[班牌]{item.name}</View>
                    <View className='button' onClick={()=>this.deleteItem(2,item)}>移除</View>
                  </View>
                )
              })
            }
            {//广播终端
              data?.RadioBroadcasts?.map((item,index)=>{
                return(
                  <View className='item' key={"admin"+index}>
                    <View className='text'>[广播]{item.name}</View>
                    <View className='button' onClick={()=>this.deleteItem(3,item)}>移除</View>
                  </View>
                )
              })
            }
            {/* {//已选删除
              data?.devics?.map((item,index)=>{
                return(
                  <View className='item' key={"admin"+index}>
                    <View className='text'>{item.deviceName}</View>
                    <View className='button' onClick={()=>this.deleteItem(4,item)}>移除</View>
                  </View>
                )
              })
            } */}
            {
              isEmpty?
              <View className='empty_box'>
                <View className='empty'>未选择设备</View>
              </View>
              :""
            }
            <View className='bottom'></View>
          </View>
          
        </LgPopLayer>
      </View>
    )
  }
}
